const express = require("express");
const router = express.Router();
const { regionListModel } = require("../model/pickUpLocation");
const { categoryListModel, skuProductListModel } = require("../model/product");
const { leaderAddressModel } = require("../model/pickUpLocation");
/*
 * 支付订单
 *
 * */
router.get("/payment/weixin/createJsapi/:orderNo", (req, res) => {
  res.send({
    code: 200,
    msg: "获取成功",
  });
});

/*
 * 根据经纬度获取地址信息
 *
 * */
router.get("/sys/region/findAllList", async (req, res) => {
  const data = await regionListModel.find();
  res.send({
    code: 200,
    msg: "获取成功",
    data,
  });
});

router.get("/search/leader/:page/:limit", async (req, res) => {
  const { limit, page, categoryId, city } = req.query;
  // const { limit, page } = req.params
  // console.log('city====', city);
  console.log(limit);
  console.log(page);
  let skip = (page - 1) * limit;
  let xx = Number(categoryId);

  let query = {regionName:city}

  const data = await leaderAddressModel.find().skip(skip).limit(limit);
  res.send({
    code: 200,
    msg: "获取成功",
    data: {
      content: data,
    },
  });
});

//点击分类
router.get("/search/sku/:page/:limit", async (req, res) => {
  const { limit, page, categoryId, title } = req.query;
  console.log(limit, page, categoryId, title);
  let skip = (page - 1) * limit;
  const data = await skuProductListModel
    .find({ title })
    .skip(skip)
    .limit(limit);
  console.log(data);
  res.send({
    code: 201,
    msg: "获取成功",
    data: {
      content: data,
    },
  });
});

// 获取具体的商店提货点单个
router.get("/user/leader/auth/selectLeader/:leaderId", async (req, res) => {
  const { leaderId } = req.params;
  const data = await leaderAddressModel.find({ leaderId })
  res.send({
    code: 200,
    msg: "获取成功",
    data,
  });
});

module.exports = router;